---
id: 6568c073d5f37fd99ab2ab0c
title: ステップ 39
challengeType: 20
dashedName: step-39
---

# --description--

Next, you will create a method that checks if a number can be inserted in a specified column of the sudoku board by checking if the number is not already present in that column for any row.

For that, within the `Board` class, create a method named `valid_in_col`.

It should take three parameters:

- `self`: representing the instance of the class.
- `col`: representing the column index.
- `num`: representing the number to be checked.

# --hints--

You should have a `valid_in_col` method.

```js
const tCode = code.replace(/\r/g, '');
const {block_body} = __helpers.python.getBlock("\n" + tCode, "class Board");
const valid = __helpers.python.getDef(block_body, "valid_in_col");
assert.exists(valid);
```

The method should take three parameters: `self`, `col`, and `num`. Order matters

```js
const tCode = code.replace(/\r/g, '');
const {function_parameters} = __helpers.python.getDef(tCode, "valid_in_col");
assert.match(function_parameters, /self\s*,\s*col\s*,\s*num/);
```

# --seed--

## --seed-contents--

```py
class Board:
    def __init__(self, board):
        self.board = board

    def __str__(self):
        upper_lines = f'\n╔═══{"╤═══"*2}{"╦═══"}{"╤═══"*2}{"╦═══"}{"╤═══"*2}╗\n'
        middle_lines = f'╟───{"┼───"*2}{"╫───"}{"┼───"*2}{"╫───"}{"┼───"*2}╢\n'
        lower_lines = f'╚═══{"╧═══"*2}{"╩═══"}{"╧═══"*2}{"╩═══"}{"╧═══"*2}╝\n'
        board_string = upper_lines
        for index, line in enumerate(self.board):
            row_list = []
            for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
                row_square = '|'.join(str(item) for item in part)
                row_list.extend(row_square)
                if square_no != 3:
                    row_list.append('║')

            row = f'║ {" ".join(row_list)} ║\n'
            row_empty = row.replace('0', ' ')
            board_string += row_empty

            if index < 8:
                if index % 3 == 2:
                    board_string += f'╠═══{"╪═══"*2}{"╬═══"}{"╪═══"*2}{"╬═══"}{"╪═══"*2}╣\n'
                else:
                    board_string += middle_lines
            else:
                board_string += lower_lines

        return board_string

    def find_empty_cell(self):
        for row, contents in enumerate(self.board):
            try:
                col = contents.index(0)
                return row, col
            except ValueError:
                pass
        return None

    def valid_in_row(self, row, num):
        return num not in self.board[row]
--fcc-editable-region--

--fcc-editable-region--
```
